const Koa = require("koa");
const bodyParser = require("koa-bodyparser");
const useRoutes = require("../router");
const cors = require("koa2-cors");
const { createServer } = require("http");
const { Server } = require("socket.io");
const { socketOnConnection } = require("./socket");

const s = require("./db");

const app = new Koa();
app.useRoutes = useRoutes;
app.use(cors());
app.use(bodyParser());
app.useRoutes();

const httpServer = createServer(app.callback());

const io = new Server(httpServer, {
  cors: {
    origin: "*",
  },
});
socketOnConnection(io);

module.exports = httpServer;
